package server.connector.http;

final class HttpHeader {
    //常量
    private static final int INITIAL_NAME_SIZE = 32;
    private static final int INITIAL_VALUE_SIZE = 64;

    public static final int MAX_NAME_SIZE = 128;
    public static final int MAX_VALUE_SIZE = 4096;
    // 实例变量
    public char[] name;
    public char[] value;
    public int nameLength;
    public int valueLength;

    protected int hashCode = 0;

    //构造器
    public HttpHeader() {
        this.name = new char[INITIAL_NAME_SIZE];
        this.value = new char[INITIAL_VALUE_SIZE];
        this.nameLength = 0;
        this.valueLength = 0;
    }
    //复位
    public void reset() {
        nameLength = 0;
        valueLength = 0;
        hashCode = 0;
    }

    //hash值由name字段决定
    //算法与String类的hashCode算法相同
    @Override
    public int hashCode() {
       if (hashCode == 0) {
           for (int i = 0; i < nameLength; i++) {
               hashCode = hashCode * 31 + name[i];
           }
       }
       return hashCode;
    }
}
